package com.atguigu.springboot.service;

import com.atguigu.springboot.bean.Employee;
import com.atguigu.springboot.bean.Region;
import com.atguigu.springboot.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Smexy on 2022/10/11
 *
 *  根据产品和公司规定的业务规范编写
 *
 *  @Service:
 *          ①给自己人看，标识这是一个业务模型服务类
 *          ②容器看到后，自动在容器中为这个注解标注的类窗口一个单例对象
 */
@Service
public class EmployeeServiceImpl implements EmployeeService
{
    // mapper = new EmployeeMapper()
    // new EmployeeMapper(): 交给容器
    // mapper =
    @Autowired
    private EmployeeMapper mapper;

    @Override
    public Employee getEmployeeById(Integer id) {

        System.out.println("查询之前要干嘛.....");

        Employee employee = mapper.getEmployeeById(id);

        System.out.println("查询之后要干嘛.....");
        return employee;
    }

    @Override
    public void insertEmployee(Employee employee) {

        System.out.println("新增之前要干嘛.....");

        mapper.insertEmployee(employee);

        System.out.println("新增之后要干嘛.....");

    }

    @Override
    public void updateEmployee(Employee employee) {

        System.out.println("更新之前要干嘛.....");

        mapper.updateEmployee(employee);

        System.out.println("更新之后要干嘛.....");

    }

    @Override
    public void deleteEmployeeById(Integer id) {

        System.out.println("删除之前要干嘛.....");

        mapper.deleteEmployeeById(id);

        System.out.println("删除之后要干嘛.....");

    }

    @Override
    public List<Employee> getAll() {

        System.out.println("查询之前要干嘛.....");

        List<Employee> emps = mapper.getAll();

        System.out.println("查询之后要干嘛.....");

        return emps;
    }

    @Override
    public List<Region> getAllRegions() {
        return mapper.getAllRegions();
    }
}
